package com.lianzhihui.romeex.mvp.model;

import android.content.Context;

import com.blankj.utilcode.util.ToastUtils;
import com.lianzhihui.romeex.MyApplication;
import com.lianzhihui.romeex.R;
import com.lianzhihui.romeex.bean.BindExchangeBean;
import com.lianzhihui.romeex.bean.ExchangeFindExchangeFlowBean;
import com.lianzhihui.romeex.bean.ExchangeFindHomeBean;
import com.lianzhihui.romeex.bean.FindExchangeInfoBean;
import com.lianzhihui.romeex.net.APIConstant;
import com.lianzhihui.romeex.net.HttpManager;
import com.lianzhihui.romeex.net.HttpManagerCallback;
import com.lianzhihui.romeex.net.ResultData;
import com.lianzhihui.romeex.utils.GsonUtil;
import com.lianzhihui.romeex.utils.LogUtil;
import com.zhouyou.http.exception.ApiException;
import com.zhouyou.http.model.HttpParams;

import io.reactivex.disposables.Disposable;

/**
 * @ProjectName: romeex
 * @Package: com.lianzhihui.romeex.mvp.model.base
 * @ClassName: InvitationModellmp
 * @Description: java类作用描述
 * @Author: zhanghong
 * @CreateDate: 2020/11/9 18:18
 * @UpdateUser: 更新者：
 * @UpdateDate: 2020/11/9 18:18
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */
public class ExchangeRecordModelImp {


    private Context context;
    ExchangeRecordModelInterface model;

    public ExchangeRecordModelImp(Context context, ExchangeRecordModelInterface model) {
        this.context = context;
        this.model = model;
    }

    /**
     * 流水记录
     */
    public Disposable requestExchangeFindExchangeFlow(String page, String pageSize, String type) {
        HttpParams params = new HttpParams();
        params.put("page", page);
        params.put("pageSize", pageSize);
        params.put("type", type);
      return   new HttpManager(context, new HttpManagerCallback() {
            @Override
            public void onSuccess(ResultData o) {
                LogUtil.info("InvitationModelImp:", o.getCode() + "");
                if (o.getCode() == 200) {
                    ExchangeFindExchangeFlowBean bean = GsonUtil.GsonToBean(o.getData(), ExchangeFindExchangeFlowBean.class);
                    model.responseSuccess(bean);
                } else {
                    model.onFailure();
                }
            }

            @Override
            public void onError(ApiException e) {
                ToastUtils.showShort(MyApplication.mContext.getResources().getString(R.string.text_net_error));
                model.onFailure();
            }
        }).post(APIConstant.EXCHANGE_FINDEXCHANGEFLOW, params);

    }

}
